package ipebg.mzk.provider.system.service.impl;

import ipebg.mzk.common.util.DirectoryUtil;
import ipebg.mzk.facade.system.bean.UserDTO;
import ipebg.mzk.facade.system.service.UserDTOService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.foxconn.shzbg.directory.dto.AccountInfo;


@Service("userDTOServiceImpl")
public class UserDTOServiceImpl implements UserDTOService{
	private static Log log = LogFactory.getLog(UserDTOServiceImpl.class);
	@Override
	public UserDTO getUserDTOByAccountName(String accountName) throws Exception {
		AccountInfo account;
		UserDTO user=null;
		try {
			account = DirectoryUtil.getDirectoryService().getAccount(accountName.toUpperCase());
			if(account!=null){
				 user=new UserDTO();
				user.setAccountName(account.getAccountName());
				user.setPersonName(account.getPersonName());
				user.setDepartmentName(account.getDepartmentName());
				user.setDepartmentName(account.getDepartmentNo());
				user.setEmail(account.getEmail());
				user.setExtension(account.getExtension());
				user.setDuty(account.getDuty());
				user.setPassword(account.getPassword());
				user.setSeniority(account.getSeniority());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.getMessage());
			e.printStackTrace();
		}
		return user;
	}

	@Override
	public boolean isValidUser(String userno, String psw) throws Exception {
		AccountInfo account;
		boolean isok=false;
		try {
			isok = DirectoryUtil.getDirectoryService().authenticate(userno, psw);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return isok;
	}

}
